package com.apptonelabs.android.controller;

import android.app.ListActivity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.view.Window;
import android.widget.ListView;
import android.widget.Toast;

import com.apptonelabs.android.model.PNREntryList;
import com.apptonelabs.android.model.PNRType;
import com.apptonelabs.android.view.PNREntryAdapter;

public class PNREntryActivity extends ListActivity {

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		// No title bar
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		PNRType type = (PNRType) getIntent().getExtras().getSerializable("pnrlisttype");
		PNREntryList obj = (PNREntryList) getIntent().getExtras().getSerializable("pnrlist");
		
		setListAdapter(new PNREntryAdapter(this, obj.getList(), type));
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// get selected items
		try {
			if(position == 1) {
				String selectedValue = (String) getListAdapter().getItem(position);
				ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
				String selected = selectedValue.split(":")[1].replaceAll("</b>", "").replaceAll("&nbsp;", "").trim();
				clipboard.setText(selected);
				Toast.makeText(this, "Copied to Clipboard : " + (selected), Toast.LENGTH_LONG).show();
				
			}
		} catch (Exception e) {
			// ignore
		}
	}
}